
class P10774 {

	public static void main(String[] args) {
		int cases = Integer.parseInt(readLn());
		for (int k = 0; k < cases; k++) {
			System.out.print("Case " + (k + 1) + ":");
			process(Integer.parseInt(readLn()));
		}
	}


	private static void process(int i) {
		boolean[] vivos = new boolean[i];
		for (int k = 0; k < i; k++) {
			vivos[k] = true;
		}
		int mortos = 0;
		int index = -1;

		long counter = -1;
		int vivo = 0;
		while (true) {
			counter++;
			while (mortos < i - 1) {
				int nextPrimo = 2;
				while (nextPrimo > 0) {
					index++;
					if (index == i) {
						index = 0;
					}

					if (vivos[index]) {
						nextPrimo--;
					}
				}
				vivos[index] = false;
				// System.out.println("Morreu! " + index);
				mortos++;
				// primosCounter++;
			}
			vivo = getVivo(vivos); 
			if (vivo == i) {
				break;
			} else {
				i = vivo;
				vivos = new boolean[i];
				for (int k = 0; k < i; k++) {
					vivos[k] = true;
				}
				mortos = 0;
				index = -1;
			}
		}
		
		System.out.println(" " + counter + " " + vivo);
	}


	private static int getVivo(boolean[] vivos) {
		int i = vivos.length;
		for (int k = 0; k < i; k++) {
			if (vivos[k]) {
				return (k + 1);
			}
		}
		return 0;
	}


	static String readLn() {
		String newLine = System.getProperty("line.separator");
		StringBuffer buffer = new StringBuffer();
		int car = -1;
		try {
			car = System.in.read();
			while ((car > 0) && (car != newLine.charAt(0))) {
				buffer.append((char) car);
				car = System.in.read();
			}
			if (car == newLine.charAt(0))
				System.in.skip(newLine.length() - 1);
		} catch (java.io.IOException e) {
			return (null);
		}
		if ((car < 0) && (buffer.length() == 0))
			return (null);
		return (buffer.toString()).trim();
	}

}
